package com.hhkj.study.admin.teacher.service.extend.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.hhkj.study.admin.teacher.entity.Teacher;
import com.hhkj.study.admin.teacher.model.podo.TeacherDo;
import com.hhkj.study.admin.teacher.model.podo.TeacherPo;
import com.hhkj.study.admin.teacher.service.base.TeacherService;
import com.hhkj.study.admin.teacher.service.extend.TeacherExtendService;
import com.ruoyi.common.base.biz.service.extend.BaseExtendServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class TeacherExtendServiceImpl extends BaseExtendServiceImpl<Teacher, TeacherDo, TeacherPo, TeacherService> implements TeacherExtendService {

    @Override
    public Teacher getByName(String name) {
        LambdaQueryWrapper<Teacher> teacherQuery = new LambdaQueryWrapper<>();
        teacherQuery.eq(Teacher::getName, name).last("LIMIT 1");
        return this.getService().getOne(teacherQuery);
    }

    @Override
    public List<Teacher> getTeacherList(List<Long> teacherIdList, List<Teacher> teacherList) {
        if (CollectionUtil.isEmpty(teacherIdList) || CollectionUtil.isEmpty(teacherList)) {
            return Lists.newArrayList();
        }
        return teacherList.stream().filter(teacher -> teacherIdList.contains(teacher.getId())).collect(Collectors.toList());
    }
}
